<template>
    <div class="container">
        <div class="title">
            <span>添加bannerItem</span>
            <span class="back" @click="back">
        <i class="iconfont icon-fanhui"></i> 返回
      </span>
        </div>
        <el-divider></el-divider>
        <el-form label-width="80px">
            <div class="wrap">
                <el-form-item label="">
                    <upload-imgs
                            ref="uploadEle"
                            :value="imgValue"
                            :rules="rules"
                            :multiple="true"
                            :min-num="1"
                            :max-num="1"
                    />
                </el-form-item>
                <el-form-item label="排序" prop="order_sort">
                    <el-input size="medium" type="number" v-model="order_sort" placeholder="请填写排序(值越大越在前)"></el-input>
                </el-form-item>
                <el-form-item class="submit">
                    <el-button type="primary" @click="getValue()">保 存</el-button>
                </el-form-item>
            </div>
        </el-form>
    </div>
</template>

<script>
import banner from '@/models/banner'
import UploadImgs from '@/components/base/upload-imgs'

export default {
  components: {
    UploadImgs,
  },
  props: {
    bannerId: {
      type: Number,
    },
    orderSort: {
      type: Number,
    },
  },
  data() {
    return {
      imgValue: [],
      order_sort: '',
      rules: {
        maxSize: 0.4,
      },
    }
  },
  watch: {
    type() {
      this.type_value = ''
    },
  },
  // eslint-disable-next-line no-empty-function
  mounted() {
    this.order_sort = this.orderSort
  },
  methods: {
    back() {
      this.$emit('addClose')
    },
    async getValue() {
      const self = this
      const imgValue = await this.$refs.uploadEle.getValue()
      const info = {
        items: [{
          banner_id: self.bannerId,
          img_id: imgValue[0].imgId,
          order_sort: self.order_sort,
        },
        ],
      }
      const res = await banner.addBanner(info)
      if (res.error_code === 0) {
        self.imgValue = []
        this.$message.success(`${res.msg}`)
        this.back()
      }
    },
    change(val) {
      this.type_value = val
    },
  },
}
</script>

<style lang="scss" scoped>
    .el-divider--horizontal {
        margin: 0
    }

    .container {
        .title {
            height: 59px;
            line-height: 59px;
            color: $parent-title-color;
            font-size: 16px;
            font-weight: 500;
            text-indent: 40px;

            .back {
                float: right;
                margin-right: 40px;
                cursor: pointer;
            }
        }

        .wrap {
            padding: 20px;
        }

        .submit {
            float: left;
        }
    }
</style>
